<?php
/*
 * @ https://EasyToYou.eu - IonCube v11 Decoder Online
 * @ PHP 7.2 & 7.3
 * @ Decoder version: 1.1.6
 * @ Release: 10/08/2022
 */

// Decoded file for php version 71.
namespace AlibabaCloud\Client\Resolver;

abstract class ApiResolver
{
    public static function __callStatic($name, $arguments)
    {
        return (new static())->__call($name, $arguments);
    }
    public function __call($api, $arguments)
    {
        $product_name = $this->getProductName();
        $class = $this->getNamespace() . "\\" . ucfirst($api);
        if(class_exists($class)) {
            if(isset($arguments[0])) {
                return $this->warpEndpoint(new $class($arguments[0]));
            }
            return $this->warpEndpoint(new $class());
        }
        throw new \AlibabaCloud\Client\Exception\ClientException($product_name . " contains no " . $api, "SDK.ApiNotFound");
    }
    public function warpEndpoint(\AlibabaCloud\Client\Request\Request $request)
    {
        $reflect = new \ReflectionObject($request);
        $product_dir = dirname(dirname($reflect->getFileName()));
        $endpoints_json = $product_dir . "/endpoints.json";
        if(file_exists($endpoints_json)) {
            $endpoints = json_decode(file_get_contents($endpoints_json), true);
            if(isset($endpoints["endpoint_map"])) {
                $request->endpointMap = $endpoints["endpoint_map"];
            }
            if(isset($endpoints["endpoint_regional"])) {
                $request->endpointRegional = $endpoints["endpoint_regional"];
            }
        }
        return $request;
    }
    private function getProductName()
    {
        $array = explode("\\", get_class($this));
        if(isset($array[3])) {
            return str_replace("ApiResolver", "", $array[3]);
        }
        throw new \AlibabaCloud\Client\Exception\ClientException("Service name not found.", "SDK.ServiceNotFound");
    }
    private function getNamespace()
    {
        $array = explode("\\", get_class($this));
        if(!isset($array[3])) {
            throw new \AlibabaCloud\Client\Exception\ClientException("Get namespace error.", "SDK.ParseError");
        }
        unset($array[3]);
        return implode("\\", $array);
    }
}

?>